/**
 * 枚举，先用文件保存字典
 */
const defaultConfig =  {

  dialogConfig: {
    width: '500px',
    draggable: true
  },
  formConfig: {
    items: [
      { label: '姓名', prop: 'name', size: 'small' },
      { label: '年龄', prop: 'age', type: 'number' },
      {
        label: '性别',
        prop: 'sex',
        type: 'radio',
        style: { width: '150px' },
        options: [
          { label: '男', value: 'man' },
          { label: '女', value: 'woman' }
        ]
      },
      {
        label: '爱好',
        prop: 'loves',
        type: 'checkbox',
        options: [
          { label: '摄影', value: 'sheying' },
          { label: '电影', value: 'dianying' }
        ]
      }
    ],
   
    buttons: [
      {
        text: '确定',
        emitName: 'confirm',
        type: 'primary',
        handler: 'funcRef: addItem'
      },
      {
        text: '取消',
        emitName: 'cancle',
        type: 'warning',
        handler: 'funcRef: closeModel'
      },
      {
        text: '重置',
        type: 'info',
        handler: 'funcRef: resetForm'
      }
    ]
  }
}
module.exports = function({ fields=[] , subject}, result){

    result.addForm = defaultConfig
    result.addForm .title = `添加2${subject}`
    result.addForm.formConfig.defaultValue = {}
    
    const columns = fields.filter(({add})=>add).map(({add:{dictRef,def,dateType,type='input'},label,prop})=>{
        if(def){
          result.addForm.formConfig.defaultValue[prop]=def
        }
        const item =  {
            type,
            label,
            prop,
            dateType,
        }
        if(dictRef){    
            item.options = "dictRef: "+dictRef
        }
        if(type==='select'){
            item. style= { width: '150px' }
        }
        return item
    })
    
    result.addForm.formConfig.items = columns
}